//
//  SSUserRedeemController.swift
//  拾舍清洁
//
//  Created by sky.wei on 2023/3/9.
//

import UIKit
import SwiftyJSON

class SSUserRedeemController: UIViewController {

    @IBOutlet weak var sureBtn: UIButton!
    @IBOutlet weak var bgView: UIView!
    @IBOutlet weak var couponTextF: UITextField!
    override func viewDidLoad() {
        super.viewDidLoad()

        sureBtn.layer.cornerRadius = 8
        sureBtn.layer.masksToBounds = true
        bgView.layer.cornerRadius = 8
        bgView.layer.masksToBounds = true
    }


    @IBAction func sureAction(_ sender: Any) {
        saveRedeemRequest()
    }
    
    //MARK: -network
    func saveRedeemRequest() {
        let redeemCode = couponTextF.text
        
        let param = [
            "phoneNo": kUserPhone,
            "redeemCode": redeemCode
                ] as! [String:AnyObject]
        SSProgressHUD.share.show()
        HttpConnectTools.share.request(urlString: APIUrl.share.userRedeem, parameters: param) { (result, error) in
            SSProgressHUD.share.dismiss()
            let json = JSON(parseJSON: result!)
            let retCode = json["retCode"].stringValue
            let retMsg = json["retMsg"].stringValue
            if(retCode == "0000"){
                self.view.makeToast("优惠券兑换成功！!")
                self.navigationController?.popViewController(animated: true)
            }else{
                self.view.makeToast(retMsg)
            }
        }
    }

    

}
